package com.css.fxfzdzzh.modules.tifData.controller;

import com.css.fxfzdzzh.base.response.RestResponse;
import com.css.fxfzdzzh.modules.basicData.entity.SysDataVersion;
import com.css.fxfzdzzh.modules.tifData.param.AspectTifComputeParam;
import com.css.fxfzdzzh.modules.tifData.param.SlopeTifComputeParam;
import com.css.fxfzdzzh.modules.tifData.service.ElevationMapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZYT
 * @date 2023年04月27日  15:00
 * DEM高程tif文件计算坡度、坡向
 * */
@Slf4j
@RestController
@RequestMapping("/tifData/")
public class ElevationMapController {
    @Autowired
    private ElevationMapService elevationMapService;

    /**
     *根据上传的坡度tif文件发布超图图层
     * */
    @PostMapping("importSlopeTif")
    public RestResponse importSlopeTif(String tifFileName) {
        try {
            return RestResponse.succeed(elevationMapService.importSlopeTif(tifFileName));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("发布失败!");
        }
    }

    /**
     *根据上传的坡向tif文件发布超图图层
     * */
    @PostMapping("importAspectTif")
    public RestResponse importAspectTif(String tifFileName) {
        try {
            return RestResponse.succeed(elevationMapService.importAspectTif(tifFileName));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("发布失败!");
        }
    }

    /**
     *读取DEM高程tif文件，计算坡度，保存tif文件
     * */
    @PostMapping("computeSlopeTif")
    public RestResponse computeSlopeTif(@RequestBody SlopeTifComputeParam slopeTifComputeParam) {
        try {
            return RestResponse.succeed(elevationMapService.computeSlopeTif(slopeTifComputeParam));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("保存失败!");
        }
    }

    /**
     *读取DEM高程tif文件，计算坡度，保存tif文件
     * */
    @PostMapping("computeAspectTif")
    public RestResponse computeAspectTif(@RequestBody AspectTifComputeParam aspectTifComputeParam) {
        try {
            return RestResponse.succeed(elevationMapService.computeAspectTif(aspectTifComputeParam));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("保存失败!");
        }
    }

    /**
     *读取坡度tif文件进行坡度分区统计（网格数、面积、占比）
     * */
    @PostMapping("countSlopeTif")
    public RestResponse countSlopeTif(@RequestBody String filePath) {
        try {
            return RestResponse.succeed(elevationMapService.countSlopeTif(filePath));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("统计失败!");
        }
    }

    /**
     *根据区域投影到6度带或3度带，计算投影面积之和（平方公里)
     * */
    @PostMapping("getAreaByGeomEpsgCount")
    public RestResponse getAreaByGeomEpsgCount(@RequestBody String geomText) {
        try {
            return RestResponse.succeed(elevationMapService.getAreaByGeomEpsgCount(geomText));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("计算失败!");
        }
    }

    /**
     *校验空间数据是否自相交
     * */
    @PostMapping("isGeomValid")
    public RestResponse isGeomValid(@RequestBody String geomText) {
        try {
            return RestResponse.succeed(elevationMapService.isGeomValid(geomText));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("校验失败!");
        }
    }

    /**
     *修复空间数据自相交，获取修复后的空间数据
     * */
    @PostMapping("makeGeomValid")
    public RestResponse makeGeomValid(@RequestBody String geomText) {
        try {
            return RestResponse.succeed(elevationMapService.makeGeomValid(geomText));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("修复失败!");
        }
    }
}
